﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlServerCe;

namespace WindowsFormsApplication1
{
    public partial class login : Form
    {
        public login()
        {
            InitializeComponent();
        }

        private void btn_login_Click(object sender, EventArgs e)
        {
            string connString = "Data Source=|DataDirectory|\\Model\\Database1.sdf";
            string query = "SELECT * FROM users WHERE Name ='"+txt_user.Text+"'";

            DataTable dT = Controller.Control.Select(query, connString);

            if (dT.Rows.Count != 1)
                MessageBox.Show("Worng username of password");

            else
            {
                string pass = (string)dT.Rows[0][2];
                if (!pass.Equals(txt_pass.Text))
                    MessageBox.Show("Worng username of password");

                else
                {
                    Globals.userID = (int) dT.Rows[0][0];
                    Globals.dept = (int)dT.Rows[0][3];
                    Globals.userName = txt_user.Text;

                    Form homee = new home();
                    homee.Owner = this;
                    homee.Show();
                    this.Hide();
                }
            }
            


        }

        private void btn_reg_Click(object sender, EventArgs e)
        {
            Form regi = new reg();
            regi.Owner = this;
            regi.Show();
            this.Hide();
        }
    }
}
